//
//  HJDNewCollectionViewCell.m
//  weibo
//
//  Created by 胡金东 on 16/3/29.
//  Copyright © 2016年 胡金东. All rights reserved.
//

#import "HJDNewCollectionViewCell.h"
#import "HJDTabBarController.h"

#import "HJDPesonalCenterViewController.h"
#import "HJDTabBarController.h"
#import "HJDLoginViewController.h"
//#import "UIView+Frame.h"
#import "RESideMenu.h"

#define HJDKeyWindow [UIApplication sharedApplication].keyWindow




@interface HJDNewCollectionViewCell()<RESideMenuDelegate>

@property (nonatomic,weak) UIImageView *imageView;

@property (nonatomic,weak) UIButton *shareButton;

@property (nonatomic,weak) UIButton *startButton;

@property (nonatomic,strong) RESideMenu *sideMenuViewController ;


@end


@implementation HJDNewCollectionViewCell

-(UIButton *)startButton
{
    if (_startButton == nil) {
        UIButton *startBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [startBtn setTitle:@"       " forState:UIControlStateNormal];
        [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [startBtn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        startBtn.frame = CGRectMake(0, 0, HJDWidth, HJDHeight);
        [startBtn addTarget:self action:@selector(startButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:startBtn];
        _startButton = startBtn;
    }
    return _startButton;
}

//懒加载，只有一张图片（imageView）
-(UIImageView *)imageView
{
    if (_imageView == nil) {
        UIImageView *imageV = [[UIImageView alloc]init];
        _imageView = imageV;
        //tableview和collection中都要用self.contentView，防止视图被覆盖
        [self.contentView addSubview:imageV];
        
    }
    return _imageView;
    
}
//布局子控件的frame
-(void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = self.bounds;
    
//    self.shareButton.center = CGPointMake(self.width * 0.5, self.height * 0.8);
    
//    self.startButton.center = CGPointMake(self.width * 0.5, self.height -85);
//    self.shareButton.frame = CGRectMake(0, 0, HJDWidth, HJDHeight);
}

-(void)setImage:(UIImage *)image
{
    _image = image;
    self.imageView.image = image;
}

//判断当前cell是否是最后一页
-(void)setIndexPath:(NSIndexPath *)indexPath count:(int)count
{
    if (indexPath.row == count -1) { // 最后一页,显示分享和开始按钮
        self.shareButton.hidden = NO;
        self.startButton.hidden = NO;
        
    }else{// 非最后一页，隐藏分享和开始按钮
        self.shareButton.hidden = YES;
        self.startButton.hidden = YES;
    
    }
}
// 点击开始微博的时候调用
-(void)startButtonClick
{
    HJDLoginViewController *login = [[HJDLoginViewController alloc]init];
    HJDKeyWindow.rootViewController = login;
    HJDLog(@"没登录");
    
//        NSData *data = [[NSUserDefaults standardUserDefaults ]valueForKey:@"userrr"];
//        NSString *info = [NSKeyedUnarchiver unarchiveObjectWithData:data];
//        NSLog(@"user---------%@-----",info);
    
//        NSDictionary * dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"userrr"];
//        NSString *existUname = dic[@"resultMap"];
//        HJDLog(@"%@",existUname);
//        if (info == nil) {
    
    
            
//        }
//        else{
//
//    // 进入tabBarVc
//    HJDTabBarController *tabBarVC = [[HJDTabBarController alloc]init];
//    HJDPesonalCenterViewController *personalVC = [[HJDPesonalCenterViewController alloc] init];
//    
//    self.sideMenuViewController = [[RESideMenu alloc]initWithContentViewController: tabBarVC leftMenuViewController:personalVC  rightMenuViewController:nil];
//    
//    self.sideMenuViewController.backgroundImage = [UIImage imageNamed:@"bg"];
//    self.sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
//    self.sideMenuViewController.delegate = self;
//    self.sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
//    self.sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
//    self.sideMenuViewController.contentViewShadowOpacity = 0.2;
//    self.sideMenuViewController.contentViewShadowRadius = 12;
//    self.sideMenuViewController.contentViewShadowEnabled = YES;
//            // 切换根控制器:可以直接把之前的根控制器清空
//            HJDKeyWindow.rootViewController = self.sideMenuViewController;
//            
//
//        }
    
}


@end
